# -*- coding: utf-8 -*-
import scrapy
from qiushibaike.items import QiushibaikeItem
# from scrapy.http.response.html import HtmlResponse

class QsbkSpider(scrapy.Spider):
    name = 'qsbk'
    allowed_domains = ['qiushibaike.com']
    start_urls = ['https://www.qiushibaike.com/8hr/page/1/']
    base_domain = 'https://www.qiushibaike.com'

    def parse(self, response):
        duanzilis = response.xpath("//div[@class='recommend-article']//li")
        for duanzili in duanzilis:
            author = duanzili.xpath(".//a[@class='recmd-user']/span/text()").get()
            title = duanzili.xpath(".//a[@class='recmd-content']/text()").get()
            item = QiushibaikeItem(title=title,author=author)
            yield item

        next_url = response.xpath("//ul[@class='pagination']/li[last()]/a/@href").get()
        if next_url=='/hot/':
            return
        yield scrapy.Request(self.base_domain+next_url,callback=self.parse)
